capture program drop Tabulate_results2019

program Tabulate_results2019, eclass


**************************************
*** Table 3, ATable 4, A Table 6  ****
**************************************
quietly {
	foreach var in Baselineprice  Price_PVirrad Price_angle Netimport LaggedIV ///
	Heterotemp Temp_ddsq  Tempghi {
use Results/Andrea/`var'bootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	replace coefnumber = 100 if coefnumber ==.


	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0


	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}

	summ estimate if coefnumber ==100
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	matrix b = b[1..25,1]'
	matrix v = (se[1..25,1])*(se[1..25,1])'
	
	matrix b1=b
	matrix v1=v
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo `var'

	
		}
	
	********************************************
	** Table 4 and ATable 9 salience results **
	********************************************
	* col 1
	********
use Results/Andrea/early_adoptersbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm,"PV_earl")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}

	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	summ estimate if var ==3 
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	
	matrix b = b[1..26,1]'
	matrix v = (se[1..26,1])*(se[1..26,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Production" "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo early_adopters

	
	* col2 
	********
	
	use Results/Andrea/Producingbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm,"producing_earl")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b		
		matrix se = `se' \ se 
		
	}

	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	summ estimate if var ==3 
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	
	matrix b = b[1..26,1]'
	matrix v = (se[1..26,1])*(se[1..26,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Production" "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo Producing

	** col 3 
	********
	
	use Results/Andrea/Importingbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm,"import_ear")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}

	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	summ estimate if var ==3 
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	
	matrix b = b[1..26,1]'
	matrix v = (se[1..26,1])*(se[1..26,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Production" "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo Importing

	
	
	
	
	
 
***************************************************
*** A1 TABLE 5 non solar income, weekends ***
***************************************************
	
	* col1 
	******
		
	use Results/Andrea/NSincomebootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm,"median")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}

	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	summ estimate if var ==3 
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	
	matrix b = b[1..26,1]'
	matrix v = (se[1..26,1])*(se[1..26,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Non-solar Income" "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo NSincome

	
	
	
	
	
	* col2 
	******
		
	use Results/Andrea/Weekendincbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm,"inc_w")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}

	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	summ estimate if var ==3 
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	
	matrix b = b[1..26,1]'
	matrix v = (se[1..26,1])*(se[1..26,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Non-solar Income" "Solar Income" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo Weekendinc

	
	
	
	
*******************************************
*** A1 TABLE 7 heterogeneity of income  ***
*******************************************
 
	
	
		
	use Results/Andrea/Hour_incomebootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "is") replace
	

	gen var = 1 if strpos(parm,"price")>0
	replace var = 2 if strpos(parm,"virt")>0



	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b
		matrix se = `se' \ se 
		
	}


	forval hour = 7(1)19{
		summ estimate if coefnumber==`hour' & var==2
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}
	
	matrix b = b[1..37,1]'
	matrix v = (se[1..37,1])*(se[1..37,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b = "Solar Income (hour 18)" ///
	"Solar Income (hour 17)" "Solar Income (hour 16)" "Solar Income (hour 15)" "Solar Income (hour 14)" ///
	"Solar Income (hour 13)" "Solar Income (hour 12)" "Solar Income (hour 11)" "Solar Income (hour 10)" ///
	"Solar Income (hour 9)" "Solar Income (hour 8)" "Solar Income (hour 7)" "Solar Income (hour 6)" ///
	"(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo Hour_income

	
	
	
	
 
*******************************************
*** A1 TABLE 8 opportunity cost test    ***
*******************************************
 
	
	
		
	use Results/Andrea/OCbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "p" "k" "is") replace
	

	gen var = 1 if strpos(parm,"peak")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm, "ocp")>0


	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b
		matrix se = `se' \ se 
		
	}


	forval hour = 7(1)19{
		summ estimate if coefnumber==`hour' & var==3
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}
	
	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	matrix b = b[1..38,1]'
	matrix v = (se[1..38,1])*(se[1..38,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b =  "Solar Income" "$\Delta$ oc (hour 18)" ///
	"$\Delta$ oc (hour 17)" "$\Delta$ oc (hour 16)" "$\Delta$ oc (hour 15)" ///
	"$\Delta$ oc (hour 14)" "$\Delta$ oc (hour 13)" "$\Delta$ oc (hour 12)" "$\Delta$ oc (hour 11)" "$\Delta$ oc (hour 10)" ///
	"$\Delta$ oc (hour 9)" "$\Delta$ oc (hour 8)" "$\Delta$ oc (hour 7)" ///
	"$\Delta$ oc (hour 6)" "(hour 23)" "(hour 22)" "(hour 21)"  "(hour 20)" "(hour 19)" ///
	"(hour 18)" "(hour 17)" "(hour 16)" "(hour 15)" "(hour 14)" "(hour 13)" "(hour 12)" "(hour 11)" ///
	"(hour 10)" "(hour 9)" "(hour 8)" "(hour 7)" "(hour 6)"  "(hour 5)"  "(hour 4)" "(hour 3)"  ///
	"(hour 2)" "(hour 1)" "Buy Price (hour 0)"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo OC
	
	

		
	use Results/Andrea/OCbootstrapresults.dta, clear

	gen coefnumber = substr(parm,-2,2)
	destring coefnumber, ignore("e" "me" "ly" "nd" "l" "p" "k" "is") replace
	

	gen var = 1 if strpos(parm,"peak")>0
	replace var = 2 if strpos(parm,"virt")>0
	replace var = 3 if strpos(parm, "ocp")>0


	matrix b=(.)
	matrix se = (.) 
	forval hour = 1(1)24{
		summ estimate if coefnumber==`hour' & var==1
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b
		matrix se = `se' \ se 
		
	}


	forval hour = 7(1)19{
		summ estimate if coefnumber==`hour' & var==3
		local b = r(mean)
		local se = r(sd)
		matrix b = `b' \ b	
		matrix se = `se' \ se 
		
	}
	
	summ estimate if  var ==2
	local b = r(mean)
	local se = r(sd)
	
	matrix b = `b' \ b
	matrix se = `se' \ se 

	
	matrix b = b[1..38,1]'
	matrix v = (se[1..38,1])*(se[1..38,1])'
	
	matrix b1=b
	matrix v1=v
	
	
	summ obs 
	local N = r(mean)
	
	summ dof
	local dof = r(mean) 
	
	summ N_clust 
	local Nclust = r(mean)
	
	local dof_adj = `dof'-(`Nclust'*23)
	
	
	ereturn post b1 v1, obs(`N') dof(`dof_adj') 

	
	matrix colnames b =  "Income" "oc18" ///
	"oc17" "oc16" "oc15" ///
	"oc14" "oc13" "oc12" "oc11" "oc10" ///
	"oc9" "oc8" "oc7" ///
	"oc6" "buy23" "buy22" "buy21"  "buy20" "buy19" ///
	"buy18" "buy17" "buy16" "buy15" "buy14" "buy13" "buy12" "buy11" ///
	"buy10" "buy9" "buy8" "buy7" "buy6"  "buy5"  "buy4" "buy3"  ///
	"buy2" "buy1" "buy0"
	
	
	ereturn repost b=b V=v,  rename
	
	eststo OC2
	
	
	
	}
	
	
	
	

	
		
	
end






